package org.feng;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

import java.util.Scanner;

/**
 * @author FengJinSong
 */
@EnableAspectJAutoProxy
@SpringBootApplication
public class SpringLearnApplication {

    private static final String STOP_COMMAND = "exit";

    public static void main(String[] args) {
        ConfigurableApplicationContext applicationContext = SpringApplication.run(SpringLearnApplication.class, args);

        Scanner input = new Scanner(System.in);
        if (input.hasNext()) {
            final String command = input.nextLine();
            // 控制台输入 exit 命令，停止spring应用，触发 bean 的销毁
            if (STOP_COMMAND.equals(command)) {
                applicationContext.close();
            }
        }
    }
}
